﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Directory.Web
{
    public partial class Admin_CategoryView : System.Web.UI.Page
    {
        protected int categoryId;
        protected string categoryIdKey = "categoryId";
        protected Directory.Model.CategoryInfo cat = Model.CategoryInfo.NullCategory;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (string.Compare(Request.RequestType.ToLower(), "post") == 0)
                {
                    //Response.Clear();
                    return;
                }

                this.RolePanel1.AllowRoles = this.RolePanel2.AllowRoles = WebSettings.GetInstance().RootCategoryAdminRole;
                if (!int.TryParse(Request.QueryString[categoryIdKey], out categoryId))
                {
                    return;
                    //Response.End();
                }
                if (categoryId == WebSettings.GetInstance().RootCategoryId)
                {
                    return;
                    //Response.End();
                }
                cat = CategoryDataProxy.GetCategory(categoryId);
                if (cat == null)
                {
                    cat = Model.CategoryInfo.NullCategory;
                }
                rptChilds.DataSource = CategoryDataProxy.GetChildsOfCategory(categoryId);
                rptChilds.DataBind();

                HttpCookie authCookie = FormsAuthentication.GetAuthCookie(Page.User.Identity.Name, false);

                hplExport.NavigateUrl = string.Format("CategoryExport.aspx?categoryid={0}&{1}={2}", categoryId, authCookie.Name, authCookie.Value);
            }
        }
    }
}